package com.bigdata.quality.config.converter;

import java.util.HashMap;
import java.util.Map;

public class DorisColumnTypeConverter implements ColumnTypeConverter {
  public static final DorisColumnTypeConverter instance = new DorisColumnTypeConverter();

  @Override
  public Map<String, String> toFlinkColumnTypeMap() {
    Map<String, String> columnTypeMap = new HashMap<>();
    // 基本数据类型映射
    columnTypeMap.put("boolean", "boolean");
    columnTypeMap.put("tinyint", "tinyint");
    columnTypeMap.put("smallint", "smallint");
    columnTypeMap.put("int", "int");
    columnTypeMap.put("bigint", "bigint");
    columnTypeMap.put("float", "float");
    columnTypeMap.put("double", "double");
    columnTypeMap.put("real", "float");
    columnTypeMap.put("year", "int");

    // 日期时间类型映射
    columnTypeMap.put("date", "date");
    columnTypeMap.put("datetime", "timestamp(6)");
    columnTypeMap.put("time", "time(6)");
    columnTypeMap.put("timestamp", "timestamp(6)");

    // 字符串类型映射
    columnTypeMap.put("char", "string");
    columnTypeMap.put("varchar", "string");
    columnTypeMap.put("string", "string");
    columnTypeMap.put("text", "string");
    columnTypeMap.put("json", "string");
    columnTypeMap.put("ipv4", "string");
    columnTypeMap.put("ipv6", "string");
    columnTypeMap.put("hll", "string");
    columnTypeMap.put("bitmap", "string");

    // 二进制类型
    columnTypeMap.put("binary", "binary(2147483647)");

    // 大整数类型
    columnTypeMap.put("largeint", "string");

    // 复杂类型
    columnTypeMap.put("array", "array");
    columnTypeMap.put("map", "map");

    // 十进制类型（需要处理精度和小数位）
    columnTypeMap.put("decimal", "decimal(38,2)");
    columnTypeMap.put("decimalv2", "decimal(38,2)");
    columnTypeMap.put("decimalv3", "decimal(38,2)");

    return columnTypeMap;
  }

  @Override
  public String convertColumnType(Map<String, String> flinkColumnTypeMap, String sourceColumnType) {
    return ColumnTypeConverter.super.convertColumnType(flinkColumnTypeMap, sourceColumnType);
  }
}
